package com.dly.hope.utils;

import com.dly.hope.constant.GlobalException;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Properties;

/**
 * @author linyu.dai
 * @project myserve
 * @description 异常资源工具类
 * @creat 2022/11/4 11:08:09
 */
@Slf4j
public class ExceptionPropertiesUtil {
    private static  Properties properties;

    static {
        try (InputStreamReader is = new InputStreamReader(Objects.requireNonNull(ExceptionPropertiesUtil.class.getClassLoader().getResourceAsStream("ExceptionMessage.properties")), StandardCharsets.UTF_8)){
            properties=new Properties();
            properties.load(is);
        } catch (IOException e) {
            log.info("加载资源文件失败");
        }
    }

    public static GlobalException getException(String key){
        String value = (String) properties.get(key);
        return new GlobalException(key,value);
    }

    public static String getMsg(String key){
        return (String) properties.get(key);
    }
}